package com.qf.service.impl;

import com.qf.dao.Credit_CardDao;
import com.qf.dao.impl.Credit_CardDaoImpl;
import com.qf.entity.Credit_Card;
import com.qf.entity.User;
import com.qf.service.Credit_CardService;

import java.util.List;

public class Credit_CardServiceImpl implements Credit_CardService {

    private Credit_CardDao cardDao = new Credit_CardDaoImpl();

    @Override
    public List<Credit_Card> findCCAll() {
        return cardDao.selectCCAll();
    }

    @Override
    public User findUIDByCCRegister(String name, String num, String phone) {
        return cardDao.selectUIDrByRegister(name, num, phone);
    }

    @Override
    public Boolean addCC(Credit_Card card) {
        int res = cardDao.insertCC(card);
        if (res >= 0){
            return true;
        }
        return false;
    }

    @Override
    public Credit_Card findOneByID(String id) {
        return cardDao.selectCCByID(id);
    }

    @Override
    public List<Credit_Card> findOneByUID(String uid) {
        return cardDao.selectCCByUID(uid);
    }

    @Override
    public Boolean editByID(double num, String id) {
        int res = cardDao.updateAmount(num,id);
        if (res >= 0){
            return true;
        }
        return false;
    }

    @Override
    public boolean jiaqian(double num, String cid) {
        int res = cardDao.jiaqian(num,cid);
        if (res >= 0){
            return true;
        }
        return false;
    }

    @Override
    public boolean addCCrepayment(double repayment, String cid) {
        int res = cardDao.updateRepaymentByID(repayment,cid);
        if (res >= 0){
            return true;
        }
        return false;
    }
}
